home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 297_01 / prlush.h < prev    next >
C/C++ Source or Header  |  1991-12-29  |  4KB  |  127 lines

  1. /* prlush.h */
  2. /* used by prlush.c */
  3. /* 12/21/91 
  4.   since we now have non deterministic builtins
  5.    a Nd frame can be used for nodeterministic builtins now 
  6.    a frame type is used to distinguish between the two
  7.   12/31/91 
  8.   Frame types have been added so that we can have nondeterministic
  9.   builtins.
  10.  */
  11.  
  12. #if TRACE_CAPABILITY
  13. #define DFRAMES_HAVE_TYPE_FIELD /* for deterministic frames */
  14. #endif
  15.  
  16. #define BASE_TRAIL      Trail_mem
  17. #define BASE_CSTACK     Dyn_mem
  18. #define BASE_SUBST     Subst_mem
  19.  
  20. /* lush return values */
  21. #define SUCCESS_LUSH_RETURN     1
  22. #define FAIL_LUSH_RETURN     2
  23. #define ABNORMAL_LUSH_RETURN     3
  24. #define FINAL_LUSH_RETURN     4
  25.  
  26.  
  27. typedef int frame_type_t;
  28. /* values for frame_type_t args : */
  29. #define ND_CLAUSE  1     /* via clause */
  30. #define ND_BUILTIN 2     /* via builtin */
  31. #define D_FRAME    0     /* deterministic */
  32.  
  33. #define STRUCT_ASSUMPTION 
  34.  
  35. /*    12/31/91 now a tested way at getting at the fields of those
  36.     stack frames. It would be inefficient to define a stack frame as the
  37.     union of non-deterministic and deterministic frames. 
  38.         You might want to do more with the type field.
  39. */
  40.  
  41. #ifdef STRUCT_ASSUMPTION
  42. /* you cant expect all compilers to accept these as lvalues ! 
  43.    i.e. FRAME_PARENT(p) = Parent (for example) is not garanteed
  44.    to pass.
  45.    if not you will need explicit intermediate variables.
  46.  */
  47. #define FRAME_PARENT(C) ((dfp_t)C)->cf_parent /* points to parent frame.
  48.                     Used to continue exection
  49.                     on successful completion
  50.                     of rule.            
  51.                      */
  52. #define FRAME_SUBST(C) ((dfp_t)C)->cf_subst   /* represents parameters of
  53.                     the clause
  54.                     */
  55. #define FRAME_GOALS(C) ((dfp_t)C)->cf_goals   /* so we know which is the
  56.                     next goal to try if the
  57.                     current goal is successful
  58.                     */
  59. #define FRAME_CLAUSE(C) ((ndfp_t)C)->cf_next.cf_clause  /* so we know which is the next
  60.                     rule to try if the goal fails
  61.                     */
  62. #define FRAME_ND_BLTIN_NEXT(C) ((ndfp_t)C)->cf_next.cf_ndb_next
  63. #define FRAME_BACKTRACK(C) ((ndfp_t)C)->cf_backtrack /* so we know which frame
  64.                     to come back to on failure 
  65.                     */
  66. #define FRAME_TRAIL(C) ((ndfp_t)C)->cf_trail    /* indicates part of trail
  67.                     which will be used to reset
  68.                     substitutions on bactracking
  69.                     */
  70. #define FRAME_TYPE(C) ((ndfp_t)C)->cf_type    /* distinguish between
  71.                        nd frames due to builtins 
  72.                        and those due to clauses 
  73.                     */
  74. typedef union 
  75.     {struct d_cframe *df; struct nd_cframe *ndf;} cframe_ptr_t;
  76.  
  77. typedef struct d_cframe {
  78.         dyn_ptr_t    cf_parent;
  79.         node_ptr_t   cf_goals;
  80.         subst_ptr_t  cf_subst;
  81. #ifdef DFRAMES_HAVE_TYPE_FIELD
  82.         frame_type_t cf_type; /* only used rarely */
  83. #endif
  84.         }*dfp_t;/* deterministic control frame */
  85.  
  86. typedef struct nd_cframe {
  87. /* first four fields same */
  88.         dyn_ptr_t    cf_parent;
  89.         node_ptr_t   cf_goals;
  90.         subst_ptr_t  cf_subst;
  91.         frame_type_t cf_type;
  92.         union {
  93.         clause_ptr_t cf_clause;
  94.         node_ptr_t   cf_ndb_next;
  95.         }cf_next;
  96.         dyn_ptr_t  cf_backtrack;
  97.         node_ptr_t ** cf_trail;
  98.         }*ndfp_t; /* non deterministic control frame */
  99.  
  100. #define SIZE_NDCFRAME sizeof(struct nd_cframe)
  101. #define SIZE_DCFRAME  sizeof(struct d_cframe)
  102.  
  103. #else
  104. /* not wonderful 
  105.  * because it relies on the assumption that all pointers have 
  106.  * the same size : 
  107.  * This version makes the type flag take up a whole pointer
  108.  */
  109.  
  110. #define  FRAME_PARENT(C) *((dyn_ptr_t *)C)
  111. #define  FRAME_SUBST(C) *((subst_ptr_t *)(C + sizeof(subst_ptr_t)))
  112. #define  FRAME_GOALS(C) *((node_ptr_t *)(C + 2*sizeof(char *)))
  113. #define  FRAME_TYPE(C) *((frame_type_t *)(C + 3*sizeof(char *)))
  114. #define  FRAME_CLAUSE(C) *((clause_ptr_t *)(C + 4*sizeof(char *)))
  115. #define  FRAME_BACKTRACK(C) *((dyn_ptr_t *)(C + 5*sizeof(char *)))
  116. #define  FRAME_TRAIL(C) *((node_ptr_t ***)(C + 6*sizeof(char *)))
  117. #define  FRAME_ND_BLTIN_NEXT(C) *((node_ptr_t *)(C + 4*sizeof(char *)))
  118.  
  119. #define SIZE_NDCFRAME 8*sizeof(char *)
  120. #define SIZE_DCFRAME  4*sizeof(char *)
  121. #endif
  122.  
  123. #define IS_BUILTIN(A) (A <= LastBuiltin)
  124.  
  125. extern atom_ptr_t LastBuiltin;
  126.  
  127.